#include "article.h"
#include "newsgroup.h"
#include <iostream>

using namespace std;

namespace client_server{
	//Constructor
	NewsGroup::NewsGroup(string pname, unsigned int pn): name(pname), number(pn) {
	}

	//destructor
	NewsGroup::~NewsGroup(){
		vector<Article*>::iterator ait;
		for(ait = articles.begin(); ait != articles.end(); ait++){
			delete *ait;
		}
	}

	void NewsGroup::insertNewArticle(Article* art){
		articles.push_back(art);
	}

	bool NewsGroup::deleteArticle(unsigned int aId){
		vector<Article*>::iterator ait;
		for(ait = articles.begin(); ait != articles.end(); ait++){		
			unsigned int articleId = (*ait)->articlenumber();
			if(articleId == aId){
				articles.erase(ait);
				return true;
			}
		}
		return false;
	}
}
